package com.wcs.exam.controller.admin;

import com.wcs.exam.common.base.Result;
import com.wcs.exam.common.base.annotation.OptLog;
import com.wcs.exam.common.base.annotation.OptLogCache;
import com.wcs.exam.common.base.page.Page;
import com.wcs.exam.controller.admin.biz.AdminPaperBiz;
import com.wcs.exam.controller.admin.req.*;
import com.wcs.exam.controller.admin.resp.AdminPaperCiteListResp;
import com.wcs.exam.controller.admin.resp.AdminPaperDetailViewResp;
import com.wcs.exam.controller.admin.resp.AdminPaperPageResp;
import com.wcs.exam.controller.admin.resp.AdminPaperViewResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Collection;
import java.util.List;

/**
 * Admin-试卷信息
 *
 * @author wcs
 * @since 2025-03-11
 */
@Tag(name = "Admin-试卷信息")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/admin/paper")
public class AdminPaperController {

    @NotNull
    private final AdminPaperBiz biz;

    @Operation(summary = "试卷信息-分页")
    @OptLog(value = "试卷信息-分页")
    @GetMapping(value = "/page")
    public Result<Page<AdminPaperPageResp>> page(@ModelAttribute AdminPaperPageReq req) {
        return biz.page(req);
    }

    @Operation(summary = "试卷信息-添加")
    @OptLog(value = "试卷信息-添加")
    @PostMapping(value = "/save")
    public Result<String> save(@RequestBody @Valid AdminPaperSaveReq req) {
        return biz.save(req);
    }

    @Operation(summary = "试卷信息-查看")
    @Parameter(name = "id", description = "主键ID", required = true)
    @OptLogCache
    @GetMapping(value = "/view")
    public Result<AdminPaperViewResp> view(@RequestParam Long id) {
        return biz.view(id);
    }

    @Operation(summary = "试卷信息-详情查看")
    @OptLog(value = "试卷信息-详情查看")
    @Parameter(name = "id", description = "主键ID", required = true)
    @GetMapping(value = "/detail/view")
    public Result<AdminPaperDetailViewResp> detailView(@RequestParam Long id) {
        return biz.detailView(id);
    }

    @Operation(summary = "试卷信息-编辑")
    @OptLog(value = "试卷信息-编辑", isUpdate = true)
    @PutMapping(value = "/edit")
    public Result<String> edit(@RequestBody @Valid AdminPaperEditReq req) {
        return biz.edit(req);
    }

    @Operation(summary = "试卷信息-编辑发布状态")
    @OptLog(value = "试卷信息-编辑发布状态")
    @PutMapping(value = "/edit/publish/status")
    public Result<String> editPublishStatus(@RequestBody @Valid AdminPaperEditPublishStatusReq req) {
        return biz.editPublishStatus(req);
    }

    @Operation(summary = "试卷信息-排序")
    @OptLog(value = "试卷信息-排序")
    @PutMapping(value = "/sort")
    public Result<String> sort(@RequestBody @Valid List<AdminPaperSortReq> reqs) {
        return biz.sort(reqs);
    }

    @Operation(summary = "试卷信息-删除")
    @Parameter(name = "id", description = "主键ID", required = true)
    @OptLog(value = "试卷信息-删除")
    @DeleteMapping(value = "/delete")
    public Result<String> delete(@RequestParam Long id) {
        return biz.delete(id);
    }

    @Operation(summary = "试卷信息-批量删除")
    @Parameter(name = "ids", description = "主键ID", required = true)
    @OptLog(value = "试卷信息-批量删除")
    @DeleteMapping(value = "/delete/batch")
    public Result<String> deleteBatch(@RequestBody Collection<Long> ids) {
        return biz.deleteBatch(ids);
    }

    @Operation(summary = "试卷信息-移动")
    @OptLog(value = "试卷信息-移动")
    @PutMapping(value = "/move")
    public Result<String> move(@RequestBody @Valid AdminPaperMoveReq req) {
        return biz.move(req);
    }

    @Operation(summary = "试卷信息-引用列表")
    @Parameter(name = "id", description = "主键ID", required = true)
    @GetMapping(value = "/cite/list")
    public Result<List<AdminPaperCiteListResp>> citeList(@RequestParam Long id) {
        return biz.citeList(id);
    }

    @Operation(summary = "试卷信息-组卷")
    @OptLog(value = "试卷信息-组卷")
    @PostMapping(value = "/compose")
    public Result<String> compose(@RequestBody @Validated AdminPaperComposeReq req) {
        return biz.compose(req);
    }
}
